class Solution {
public:
    bool lemonadeChange(vector<int>& bills) {
        int five = 0, ten = 0;
        for(auto e: bills)
        {
            if(e == 5)
            {
                five++;
            }
            else if(e == 10)
            {
                if(five != 0)
                {
                    five--;
                    ten++;
                }
                else{
                    return false;
                }
            }
            else{
                // e == 20
                if(ten != 0)
                {
                    if(five != 0)
                    {
                        ten--;
                        five--;
                    }
                    else{
                        return false;
                    }
                }
                else if(five >= 3)
                {
                    five -= 3;
                }
                else{
                    return false;
                }
            }
        }
        return true;
    }
};